#pragma once

#include <thread>
#include <atomic>
#include <string>
#include <memory>

#include "shm_utils.h" 

class MarketPersistor {
public:
    explicit MarketPersistor(MARKETStruct* market_ptr);
    ~MarketPersistor();

    void start();
    void stop();

private:
    void persist_loop();

    void write_price_level();
    void write_order();
    void write_trade();
    void write_order_rsp();

    std::string get_output_path(const std::string& name) const;

private:
    std::thread worker_;
    MARKETStruct* market_ptr_;
    std::atomic<bool> running_{false};

    // ✅ 各类共享内存的读取游标（用于增量写入）
    size_t last_price_level_index_ = 0;
    size_t last_order_index_ = 0;
    size_t last_trade_index_ = 0;
    size_t last_order_rsp_index_ = 0;
};
